<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    
<%@page import="utils.SCmd"%>
<%@page import="utils.SeU"%>
<%@page import="javax.naming.Context"%>
<%@page import="swimv2.session.*"%>
<%@page import="swimv2.entity.*"%>
<%@page import="java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<link href="css/layout_2_col.css" rel="stylesheet" type="text/css">
</head>
<body>

<%
	//Recupero dei parametri e settaggio dei flag
	boolean logged = false;
	if(session.getAttribute(SeU.STATUS_ATTRIBUTE)=="user")
	{
		logged = true;
	}
%>

<div id="main-wrapper-o">
		<div id="main-wrapper-i">
			<div id="header-o">
				<div id="header-i">
					<div id="logo_block">
						<a href="<%= response.encodeURL("Home") %>">
							<h2>Swim</h2>
						</a>
					</div>
				
					<div id="search_box">
						<form>
							<input type="text" name="<%= SeU.USERNAME_ATTRIBUTE %>" />
							<input type="submit" value="search">
						</form>
					</div>
				</div>
			</div>
			<!-- END HEADER-->
			
			<div id="side_left_o">
				<div id="side_left_i">
				
					<ul>
					<%
					
						List<Response> rl = (List<Response>)session.getAttribute(SeU.CONVERSATIONS_ATTRIBUTE);
						for(Response r : rl)
						{
							%>
								<li>
									<a href="<%=response.encodeURL("Message?"+SeU.RESPONSE_ATTRIBUTE_ID+"="+r.getId()) %>">
										<%= r.getObject() %>
									</a>
								</li>			
							<%
						}
					%>
					</ul>
				</div>
			</div>
			
			
			<div id="main-content-0">
				<div id="main-content-i">
					<h2>MESSAGGI</h2>
					<%
					
					List<Message> ml = (List<Message>)session.getAttribute(SeU.CONVERSATION_ATTRIBUTE);
					
					
					Integer resp_id = 0;
					Integer req_id = 0;
					if(ml.size()>1)
					{
						resp_id = ml.get(1).getId();
						req_id = ml.get(0).getId();
					}
					else if (ml.size()>0)
					{
						resp_id = null;
						req_id = ml.get(0).getId();
					}
					
					
					for(Message m : ml)
					{
					%>
						<div>
							<h4>
								<%= m.getObject() %>
							</h4>
							<p>
								<%= m.getMessage() %>
							</p>
						</div>
					
					<%
					}
					%>
					
					<form action='<%= response.encodeRedirectURL("Message") %>'>
						Object: <input type="text" name="<%= SeU.SUBJECT_ATTRIBUTE %>"><br>
						Text: <input type="text" name="<%= SeU.TEXT_ATTRIBUTE %>"><br>
						<input type="hidden" name="<%=SCmd.SERVLET_COMMAND %>" value="<%=SCmd.ADD_RESPONSE %>">
						<input type="hidden" name="<%=SeU.RESPONSE_ATTRIBUTE_ID %>" value="<%=resp_id %>">
						<input type="hidden" name="<%=SeU.REQUEST_ATTRIBUTE_ID %>" value="<%= req_id %>">
						<input type="submit" value="Invia">
					</form>
					
				</div>
			</div><!-- END  MAIN CONTENT      -->
			<div id="side_right_o">
				<div id="side_right_i">
				
					<h2>Right</h2>
				
				</div>
			</div>
			<div id="clear"></div>
			<div id="footer_o">
				<div id="footer_i">
					
					<h2>FOOTER</h2>
					
				</div>
			</div>
		</div>
	</div><!--END WRAPPER-->
</body>
</html>